package Lecture9;

import java.util.Arrays;

public class BuildHeap {

	public static void main(String[] args) {

		int[] array = {3,5,7,2,9,7,4,4,6,7,3,2,1};
		//int[] array = {901,882,453,654,5555,86,7,18,109,300};

		//int[] array = { 3, 537, 24, 500, 436,355,3,248,6,449,2,326,322,1};
		System.out.println(Arrays.toString(array));

		
		for(int i = 0; i < array.length; i++)
		{
			
			int nodeIndex = i;
			while (nodeIndex != 0)
			{
				System.out.println(nodeIndex + " node");
				
				int parentIndex = (nodeIndex-1)/2;
				
				System.out.println(parentIndex + " parent");
				
				if(array[parentIndex] < array[nodeIndex])
				{
					int temp = array[parentIndex];
					array[parentIndex] = array[nodeIndex];
					array[nodeIndex] = temp;
				}
				nodeIndex = parentIndex;
				System.out.println(Arrays.toString(array));
				System.out.println();

			}
			
			System.out.println("n");
			//System.out.println(Arrays.toString(array));
		}
		
		//System.out.println(Arrays.toString(array));

		
		
		
	}

}
